class Dialogs {

	/**************************** 信息弹出层 ****************************/

	static message(messages: [
		{
			title: string,
			content: string
		}
	]): egret.Sprite {
		let messageCon: egret.Sprite = new egret.Sprite();
		let messageConBg: egret.Shape = new egret.Shape();
		let btnClose: egret.Shape = new egret.Shape();
		let scrollView:egret.ScrollView = new egret.ScrollView();
		let scrollCon: egret.Sprite = new egret.Sprite();

		//载入容器
		messageCon.addChild(messageConBg);
		messageCon.addChild(btnClose);
		messageCon.addChild(scrollView);
		scrollView.setContent(scrollCon);

		//信息窗体加入舞台后再设置样式
		messageCon.addEventListener(egret.Event.ADDED_TO_STAGE, () => {
			//设置信息窗体样式
			messageCon.width = messageCon.stage.stageWidth * 0.8;
			if (scrollCon.height > messageCon.stage.stageHeight * 0.8) {
				messageCon.height = messageCon.stage.stageHeight * 0.8;
			}
			messageCon.height = messageCon.stage.stageHeight * 0.8;
			messageCon.anchorOffsetX = messageCon.width / 2;
			messageCon.anchorOffsetY = messageCon.height / 2;
			messageCon.x = messageCon.stage.stageWidth / 2;
			messageCon.y = messageCon.stage.stageHeight / 2;

			//绘制信息窗体背景样式
			messageConBg.graphics.clear();
			messageConBg.graphics.beginFill(0x000000, 0.8);
			messageConBg.graphics.drawRect(0, 0, messageConBg.parent.width, messageConBg.parent.height);
			messageConBg.graphics.endFill();

			//设置关闭按钮样式
			btnClose.anchorOffsetX = btnClose.width;
			btnClose.x = btnClose.parent.width - 20;
			
			//设置滚动视图样式
			scrollView.width = scrollView.parent.width - scrollView.x * 2;
			scrollView.height = scrollView.parent.height - scrollView.y * 2;

			//设置滚动内容样式
			scrollCon.width = scrollCon.parent.width;
		}, messageCon);

		//绘制关闭按钮
		btnClose.graphics.lineStyle(6, 0xffffff);
		btnClose.graphics.moveTo(6, 6);
		btnClose.graphics.lineTo(26, 26);
		btnClose.graphics.moveTo(26, 6);
		btnClose.graphics.lineTo(6, 26);
		btnClose.graphics.lineStyle(0);
		btnClose.graphics.beginFill(0xffffff, 0);
		btnClose.graphics.drawRect(0, 0, 32, 32);
		btnClose.graphics.endFill();
		btnClose.y = 20;
		btnClose.touchEnabled = true;
		btnClose.addEventListener(egret.TouchEvent.TOUCH_TAP, () => {
			Effect.bounceOut(messageCon, messageCon.stage);
		}, messageCon);

		//设置滚动视图样式
		scrollView.x = 45;
		scrollView.y = btnClose.y + btnClose.height + 20;

		//循环遍历传入的信息内容
		messages.forEach((value, index) => {
			let thisTitle: egret.TextField = new egret.TextField();
			let thisContent: egret.TextField = new egret.TextField();

			//设置标题样式
			thisTitle.text = value.title;
			thisTitle.size = 36;
			thisTitle.bold = true;
			thisContent.lineSpacing = 20;
			thisTitle.textAlign = egret.HorizontalAlign.CENTER;
			thisTitle.addEventListener(egret.Event.ADDED_TO_STAGE, () => {
				let prev = thisTitle.parent.$children[index * 2 - 1];
				thisTitle.width = thisTitle.parent.width;
				prev ? thisTitle.y = prev.y + prev.height + 56 : "";
			}, messageCon);
			scrollCon.addChild(thisTitle);

			//设置内容样式
			thisContent.text = value.content;
			thisContent.size = 24;
			thisContent.lineSpacing = 20;
			thisContent.addEventListener(egret.Event.ADDED_TO_STAGE, () => {
				thisContent.width = thisContent.parent.width;
				thisContent.y = thisTitle.y + thisTitle.height + 45;
			}, messageCon);
			scrollCon.addChild(thisContent);
		});

		//返回信息窗体
		return messageCon;
	}


	/**************************** 分享弹出层 ****************************/

	static share(message) {
		let shareCon: egret.Sprite = new egret.Sprite();
		let shareBg: egret.Shape = new egret.Shape();
		let shareFrame: egret.Sprite = new egret.Sprite();
		let shareFramebg: egret.Shape = new egret.Shape();
		let shareText: egret.TextField = new egret.TextField();
		let borderWidth: number = 10;
		let shareFrameWidth: number;
		let shareFrameHeight: number;
		let shareFrameMargin: number = 120;
		let shareFramePadding: number = 20;
		let maxWidth: number;
		let shareTextWidth: number;

		//载入容器
		shareCon.addChild(shareBg);
		shareCon.addChild(shareFrame);
		shareFrame.addChild(shareText);
		shareFrame.addChild(shareFramebg);

		//信息窗体加入舞台后再设置样式
		shareCon.addEventListener(egret.Event.ADDED_TO_STAGE, () => {
			let stageWidth = shareCon.stage.stageWidth;
			let stageHeight = shareCon.stage.stageHeight;

			//绘制背景
			shareBg.graphics.clear();
			shareBg.graphics.beginFill(0x000000, 0.8);
			shareBg.graphics.drawRect(0, 0, stageWidth, stageHeight);
			shareBg.graphics.endFill();

			//设置信息内容
			shareText.text = message;
			shareText.size = 40;
			shareText.bold = true;
			shareText.x = shareFramePadding + borderWidth / 2;
			shareText.y = shareFramePadding + borderWidth / 2;
			shareText.lineSpacing = 16;
			maxWidth = stageWidth - shareFramePadding * 2 - borderWidth - shareFrameMargin * 2;
			shareText.width > maxWidth ? shareText.width = maxWidth : "";

			//绘制信息窗口背景样式
			shareFrameWidth = shareText.width + shareFramePadding * 2;
			shareFrameHeight = shareText.height + shareFramePadding * 2;
			shareFramebg.graphics.lineStyle(borderWidth, 0xffffff);
			shareFramebg.graphics.drawRect(borderWidth / 2, borderWidth / 2, shareFrameWidth, shareFrameHeight);
			shareFramebg.graphics.moveTo(shareFrameWidth + borderWidth / 2, borderWidth / 2);
			shareFramebg.graphics.lineTo(shareFrameWidth + 80, -80);
			shareFramebg.graphics.moveTo(shareFrameWidth + 80, -80);
			shareFramebg.graphics.lineTo(shareFrameWidth + 20, -80);
			shareFramebg.graphics.moveTo(shareFrameWidth + 80, -80);
			shareFramebg.graphics.lineTo(shareFrameWidth + 80, -20);

			//设置信息窗口样式
			shareFrame.anchorOffsetX = shareFrame.width;
			shareFrame.x = stageWidth - shareFrameMargin + 80;
			shareFrame.y = shareFrameMargin;
		}, shareCon);

		//监听分享背景事件
		shareBg.touchEnabled = true;
		shareBg.addEventListener(egret.TouchEvent.TOUCH_TAP, () => {
			Effect.fadeOut(shareCon, shareCon.stage);
		}, shareCon);

		//返回信息窗体
		return shareCon;
	}
}